package org.jeecg.modules.wlhy.hyvehicle.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.modules.wlhy.hydriver.entity.HyDriverReport;
import org.jeecg.modules.wlhy.hyvehicle.entity.HyVehicleReport;
import org.jeecg.modules.wlhy.hyvehicle.mapper.HyVehicleReportMapper;
import org.jeecg.modules.wlhy.hyvehicle.service.IHyVehicleReportService;
import org.springframework.stereotype.Service;

/**
 * @Description: hy_vehicle_report
 * @Author: jeecg-boot
 * @Date:   2022-11-17
 * @Version: V1.0
 */
@Slf4j
@Service
public class HyVehicleReportServiceImpl extends ServiceImpl<HyVehicleReportMapper, HyVehicleReport> implements IHyVehicleReportService {



    @Override
    public boolean checkUploadStatus(String vehicleId, int reportPlatformType){

        LambdaQueryWrapper <HyVehicleReport> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(HyVehicleReport::getVehicleId,vehicleId);
        queryWrapper.eq(HyVehicleReport::getReportPlatformType,reportPlatformType);
        HyVehicleReport hyVehicleReport =  this.getOne(queryWrapper);
        if(hyVehicleReport != null ){
            if("1".equals( hyVehicleReport.getVehicleUploadStatus())){
                return  true;
            }
        }
        return false;

    }

    @Override
    public boolean saveVehicleReport(HyVehicleReport hyVehicleReport){
        HyVehicleReport report = this.getOne(new LambdaQueryWrapper<HyVehicleReport>()
                .eq(HyVehicleReport::getVehicleId, hyVehicleReport.getVehicleId())
                .eq(HyVehicleReport::getReportPlatformType, hyVehicleReport.getReportPlatformType())
                .eq(HyVehicleReport::getCompanyId, hyVehicleReport.getCompanyId()));

        if (null != report) {
            hyVehicleReport.setId(report.getId());
            return this.updateById(hyVehicleReport);
        }

        return this.save(hyVehicleReport);
    }

    @Override
    public boolean checkUploadStatus(String vehicleId, String companyId, int reportPlatformType) {
        LambdaQueryWrapper<HyVehicleReport> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(HyVehicleReport::getVehicleId, vehicleId);
        queryWrapper.eq(HyVehicleReport::getReportPlatformType, reportPlatformType);
        queryWrapper.eq(HyVehicleReport::getCompanyId, companyId);
        HyVehicleReport hyVehicleReport =  this.getOne(queryWrapper);
        if (hyVehicleReport != null ) {
            if ("1".equals(hyVehicleReport.getVehicleUploadStatus())) {
                return true;
            }
        }

        return false;
    }


}
